//
//  JMProductHeaderView.m
//  NewiOSProject
//
//  Created by JMMac on 31.1.24.
//  Copyright © 2024 范智渊. All rights reserved.
//

#import "JMProductHeaderView.h"

@implementation JMProductHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        _headView = [[UIView alloc]initWithFrame:(CGRectMake(0, 0, kAppW(), 314))];
        [self addSubview:_headView];
        _bgImgV = [[UIImageView alloc]initWithFrame:(CGRectMake(0, 0, kAppW(), 150))];
        [_headView addSubview:_bgImgV];
        [_bgImgV setRoundedCorners:(UIRectCornerBottomLeft |UIRectCornerBottomRight) radii:60];
        _bgImgV.backgroundColor = Hex_Str_COLOR(@"#3C57F8");
        self.backgroundColor = WhiteColor();

        
        _priceTitleLab = [JMControl createLabelWithFrame:(CGRectMake(24, 36, kAppW(), 20)) Font:Font(15) Text:@"Monto del préstamo($)" color:WhiteColor()];
        [_headView addSubview:_priceTitleLab];
       
        _priceLab = [JMControl createLabelWithFrame:(CGRectMake(kAppW()-130, _priceTitleLab.bottom+16, 130, 45)) Font:mediumFont(32) Text:@"" color:WhiteColor()];
        [_headView addSubview:_priceLab];
        _priceLab.centerY = _priceTitleLab.centerY;
        
        
        _timeTItleLab = [JMControl createLabelWithFrame:(CGRectMake(24,_priceTitleLab.bottom+36, kAppW(), 20)) Font:Font(15) Text:@"Plazo del préstamo(Días)" color:WhiteColor()];
        [_headView addSubview:_timeTItleLab];
       
        _timeLab = [JMControl createLabelWithFrame:(CGRectMake(_priceLab.left, _priceTitleLab.bottom+16, kAppW(), 45)) Font:mediumFont(32) Text:@"" color:WhiteColor()];
        [_headView addSubview:_timeLab];
        _timeLab.centerY = _timeTItleLab.centerY;
        
        UILabel *soloLab = [JMControl createLabelWithFrame:(CGRectMake(0, _bgImgV.bottom+24, 150, 24)) Font:fontWithWeight(17, UIFontWeightMedium) Text:@"Detalles del préstamo" color:Hex_Str_COLOR(@"#222222")];
        [self addSubview:soloLab];
        soloLab.backgroundColor = WhiteColor();
        soloLab.textAlignment = 1;
        soloLab.centerX = kAppW()/2;
        
        UIView *lineV = [[UIView alloc]initWithFrame:(CGRectMake(0, 0, 198, 2))];
        lineV.backgroundColor = Hex_Str_COLOR(@"#3C57F8");
        [self addSubview:lineV];
        [self sendSubviewToBack:lineV];
        lineV.center = soloLab.center;
        CGFloat w = CalculateLabelWidthWithLab(soloLab)+16;
        soloLab.width = w;
        soloLab.centerX = kAppW()/2;
        lineV.width = w+16+48;
        lineV.centerX = soloLab.centerX;
        
        self.height = soloLab.bottom+24;
    }
    return self;
}
-(void)setInfoModel:(JMProductModel *)infoModel{
    _infoModel = infoModel;
    _priceLab.text = infoModel.loanAmount.stringValue;
    _timeLab.text = infoModel.term.stringValue;
}
@end

